package com.bankLogisticsSys;

import com.bankLogisticsSys.controller.AcceptController;
import com.bankLogisticsSys.controller.GetController;
import com.bankLogisticsSys.controller.LoginController;
import com.bankLogisticsSys.controller.ManageExpressController;
import com.bankLogisticsSys.controller.ManageIndexController;
import com.bankLogisticsSys.controller.ManageMonitorController;
import com.bankLogisticsSys.controller.ManageNetWorkController;
import com.bankLogisticsSys.controller.ManagePackageController;
import com.bankLogisticsSys.controller.ManageReportController;
import com.bankLogisticsSys.controller.ManageUserController;
import com.bankLogisticsSys.controller.MenuApiController;
import com.bankLogisticsSys.controller.PackController;
import com.bankLogisticsSys.controller.ReceiveController;
import com.bankLogisticsSys.controller.SendController;
import com.bankLogisticsSys.controller.TagApiController;
import com.bankLogisticsSys.controller.WeixinApiController;
import com.bankLogisticsSys.controller.WeixinMsgController;
import com.bankLogisticsSys.model._MappingKit;
import com.bankLogisticsSys.share.ShareController;
import com.bankLogisticsSys.usercontroller.UserController;
import com.bankLogisticsSys.weboauth2.RedirectUri;
import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.core.JFinal;
import com.jfinal.kit.PathKit;
import com.jfinal.kit.PropKit;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.cron4j.Cron4jPlugin;
import com.jfinal.plugin.druid.DruidPlugin;
import com.jfinal.plugin.redis.RedisPlugin;
import com.jfinal.template.Engine;

/** 
* @author 作者 :		xueyu 
* @date 创建时间:		2017年6月19日 下午4:53:28
* @version 版本:				 
* @description:		
*/

public class BankLogisticsSysConfig extends JFinalConfig {


	public static void main(String[] args) {
		/**
		 * 特别注意：Eclipse 之下建议的启动方式
		 */
		JFinal.start("WebRoot", 80, "/", 5);

		/**
		 * 特别注意：IDEA 之下建议的启动方式，仅比 eclipse 之下少了最后一个参数
		 */
		// JFinal.start("WebRoot", 80, "/");
	}

	@Override
	public void configConstant(Constants me) {
		// 加载少量必要配置，随后可用PropKit.get(...)获取值
		PropKit.use("databaseConfig.txt");
		me.setDevMode(PropKit.getBoolean("devMode", true));
		me.setError500View("/WEB-INF/500Page.html");
	}

	@Override
	public void configRoute(Routes me) {
		me.add("/weixin", LoginController.class);
		me.add("/msg", WeixinMsgController.class);
		me.add("/api", WeixinApiController.class, "/api");
		me.add("/oauth2",RedirectUri.class);
		me.add("/user",UserController.class);
		me.add("/jssdk",ShareController.class,"_front");
		me.add("/menu",MenuApiController.class);
		me.add("/tag", TagApiController.class);
		me.add("/weixin/get", GetController.class);
		me.add("/weixin/send", SendController.class);
		me.add("/weixin/pack", PackController.class);
		me.add("/weixin/accept", AcceptController.class);
		me.add("/weixin/receive", ReceiveController.class);
		me.add("/manage", ManageIndexController.class);
		me.add("/manage/user", ManageUserController.class);
		me.add("/manage/network", ManageNetWorkController.class);
		me.add("/manage/package", ManagePackageController.class);
		me.add("/manage/express", ManageExpressController.class);
		me.add("/manage/monitor", ManageMonitorController.class);
		me.add("/manage/report", ManageReportController.class);
	}

	@Override
	public void configEngine(Engine me) {
		me.addSharedObject("HOSTRESOUCE_PATH", "http://fiberkenzo.com");

	}

	public static DruidPlugin createDruidPlugin() {
		return new DruidPlugin(PropKit.get("jdbcUrl"), PropKit.get("user"), PropKit.get("password").trim());
	}

	/**
	 * 配置插件
	 */
	public void configPlugin(Plugins me) {
		// 配置C3p0数据库连接池插件
		DruidPlugin druidPlugin = createDruidPlugin();
		me.add(druidPlugin);

		// 配置ActiveRecord插件
		ActiveRecordPlugin arp = new ActiveRecordPlugin(druidPlugin);
		// 所有映射在 MappingKit 中自动化搞定
		arp.setBaseSqlTemplatePath(PathKit.getRootClassPath());
		arp.addSqlTemplate("manageSQL.sql");
		_MappingKit.mapping(arp);
		me.add(arp);
		
		//用于缓存物流操作 配置redis插件
		RedisPlugin redis = new RedisPlugin("action", "localhost");
		me.add(redis);
		
		Cron4jPlugin cp = new Cron4jPlugin("Cron4jConfig.txt");
		me.add(cp);
	}

	@Override
	public void configInterceptor(Interceptors me) {
		// TODO Auto-generated method stub

	}

	@Override
	public void configHandler(Handlers me) {
		// TODO Auto-generated method stub

	}

}
